import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, Index } from 'typeorm';
import { Novel } from './novel.entity';

@Entity('chapters')
@Index(['novelId', 'chapterIndex'], { unique: true })
export class Chapter {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column('text')
  content: string;

  @Column()
  chapterIndex: number;

  @Column({ nullable: true })
  sourceChapterId: string;

  @Column({ default: 0 })
  wordCount: number;

  @CreateDateColumn()
  createdAt: Date;

  @ManyToOne(() => Novel, novel => novel.chapters, { onDelete: 'CASCADE' })
  novel: Novel;

  @Column()
  novelId: number;
}